Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.default = _default;

var _api = _interopRequireDefault(require("../../../../utils/api")), _util = _interopRequireDefault(require("../../../../public/utils/util"));

function _interopRequireDefault(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var AI = [ 0, 1, 2, 3 ], AI_TYPE = [ "累计", "昨天", "最近7天", "最近30天" ], LIMIT = 18, itemText = [ "客户互动值", "产品推广度", "官网推广度", "销售主动性", "获客能力值", "个人魅力值" ];

function _default() {
    var d = null, s = 0, n = !1, l = 0;
    return {
        init: function(t) {
            (d = t).setData({
                aiIndex: 0,
                AI_TYPE: AI_TYPE,
                aiList: []
            });
        },
        onPullDownRefresh: function() {
            this.loadData(!0, wx.stopPullDownRefresh);
        },
        onReachBottom: function() {
            n || this.loadData();
        },
        gotoSingleView: function(t, a) {
            var i = d.data, e = i.aiList, n = i.card, r = e[t][a], u = getCurrentPages()[0];
            u.$put("card.data", Object.assign({
                guid: n.guid
            }, r)), u.$route("/pages/radar/singleuser/singleuser");
        },
        changeAiIndex: function(t) {
            d.setData({
                aiIndex: t
            }), this.loadData(!0);
        },
        loadData: function(t, a) {
            t && (l = s = 0);
            var i = d.data, e = i.aiIndex, n = i.isMasses, r = i.card, u = i.department;
            this[n ? "loadSingleUser" : "loadAllUserLists"]({
                loading: !0,
                data: {
                    guid: d.data.card.guid,
                    timetype: AI[e],
                    cardid: r.cardid,
                    catid: u.catid,
                    limit: LIMIT,
                    offset: s
                },
                complete: a
            }, t);
        },
        loadAllUserLists: function(t, a) {
            var i = this;
            _api.default.minicard.analysis.userlistsv2(t).then(function(t) {
                return i.formatAiList(a, t.data.list);
            });
        },
        loadSingleUser: function(t, a) {
            var i = this;
            _api.default.minicard.analysis.userintelligentviewv2(t).then(function(t) {
                return i.formatAiList(a, [ t.data ]);
            });
        },
        formatAiList: function(t, a) {
            var i = t ? [] : d.data.aiList;
            a = _util.default.addThumbToList(a).map(function(t, a) {
                return t.index = l + a, t;
            });
            var e = [];
            e = t ? (e.push(a.slice(0, 1)), e.push(a.slice(1, 3)), e.concat(_util.default.chunk(a.slice(3), 3))) : i.concat(_util.default.chunk(a, 3)), 
            d.setData({
                aiList: e
            }), l += a.length, s += LIMIT, n = a.length < LIMIT, this.initRadarData(a);
        },
        initRadarData: function(t) {
            var r = this;
            t.forEach(function(t) {
                var a = t.index, i = 0 === a, e = d.selectComponent("#chart-dom-ai" + a), n = r.getRadarData(i, t);
                e.init(n, r.getRadarRadius(i, a));
            });
        },
        getRadarRadius: function(t, a) {
            return t ? 15 : 1 === a || 2 === a ? 10 : 5;
        },
        getRadarData: function(t, a) {
            var i = [ [ "", a.productspreadrate, "#53d052" ], [ "", a.sitespreadrate, "#3dc93c" ], [ "", a.initiativerate, "#22c220" ], [ "", a.guestrate, "#9de49c" ], [ "", a.charmrate, "#84dd83" ] ];
            return t && (i = i.map(function(t, a) {
                return t[0] = itemText[a], t;
            })), i;
        }
    };
}